img = new Array();
var channelId = getvl('channelId');
var jName = getCookie('Jname');
var id;
//我的权限数组
var arrayTitle = new Array; 
selectOne();
$(document).ready(function() {
	findMyCatalogue()
});

function selectOne(){
	$.ajax({
		url: urlcore + "/api/channelBase/selectByChannelId?channelId="+channelId,
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			var n = data.data;
			id = n.id;
			$("#name").val(n.name);
			$("#address").val(n.address);
			$("#open_shop_time").val(n.openShopTime);
			$("#lease_time").val(n.leaseTime);
			$("#boss_phone").val(n.bossPhone);
			$("#assistant_count").val(n.assistantCount);
			$("#appointment_phone").val(n.appointmentPhone);
			$("#members_count").val(n.membersCount);
			$("#manager_phone").val(n.managerPhone);
			$("#market_researchers").val(n.marketResearchers);
			$("#beauty_bed_count").val(n.beautyBedCount);
			$("#area").val(n.area);
			$("#business").val(n.business);
			$("#add_members_month").val(n.addMembersMonth);
			$("#add_members_month_money").val(n.addMembersMonthMoney);
			$("#rent_money").val(n.rentMoney);
			$("#month_renewal_count").val(n.monthRenewalCount);
			$("#month_renewal_money").val(n.monthRenewalMoney);
			$("#beizhuMsg").val(n.beizhuMsg);
			//处理图片
			var imgs = new Array();
			if(n.img1 != null){
				imgs.push(n.img1.split("***"));
			}
			if(n.img2 != null){
				imgs.push(n.img2.split("***"));
			}
			if(n.img3 != null){
				imgs.push(n.img3.split("***"));
			}
			if(n.img4 != null){
				imgs.push(n.img4.split("***"));
			}
			if(n.img5 != null){
				imgs.push(n.img5.split("***"));
			}
			if(n.img6 != null){
				imgs.push(n.img6.split("***"));
			}
			if(n.img7 != null){
				imgs.push(n.img7.split("***"));
			}
			if(n.img8 != null){
				imgs.push(n.img8.split("***"));
			}
			for(j = 0; j <imgs.length; j++){
				if(imgs[j] !== null && imgs[j] !== undefined && imgs[j] !== ''){
					var k = j+1;
					for(i = 0; i <imgs[j].length; i++){
						var str = '<img width="200px" height="150px" src="'+imgs[j][i]+'" />'
						$("#oldImg"+k).append(str);
					}
					
				}
			}
			
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
}
	
function saveMsg(){
	var name = $("#name").val();
	var address = $("#address").val();
	var open_shop_time = $("#open_shop_time").val();
	var lease_time = $("#lease_time").val();
	var boss_phone = $("#boss_phone").val();
	var assistant_count = $("#assistant_count").val();
	var appointment_phone = $("#appointment_phone").val();
	var members_count = $("#members_count").val();
	var manager_phone = $("#manager_phone").val();
	var market_researchers = $("#market_researchers").val();
	var beauty_bed_count = $("#beauty_bed_count").val();
	var area = $("#area").val();
	var business = $("#business").val();
	var add_members_month = $("#add_members_month").val();
	var add_members_month_money = $("#add_members_month_money").val();
	var rent_money = $("#rent_money").val();
	var month_renewal_count = $("#month_renewal_count").val();
	var month_renewal_money = $("#month_renewal_money").val();
	var beizhuMsg = $("#beizhuMsg").val();
	
	var urlto = "/api/channelBase/add";
	if(id != null){
		urlto = "/api/channelBase/update";
	}
	
	
	$.ajax({
		url: urlcore + urlto,
		data:JSON.stringify({
			"id":id,
			"channelId":channelId,
			"name":name,
			"address":address,
			"openShopTime":open_shop_time,
			"leaseTime":lease_time,
			"bossPhone":boss_phone,
			"assistantCount":assistant_count,
			"appointmentPhone":appointment_phone,
			"membersCount":members_count,
			"managerPhone":manager_phone,
			"marketResearchers":market_researchers,
			"beautyBedCount":beauty_bed_count,
			"area":area,
			"business":business,
			"addMembersMonth":add_members_month,
			"addMembersMonthMoney":add_members_month_money,
			"rentMoney":rent_money,
			"monthRenewalCount":month_renewal_count,
			"monthRenewalMoney":month_renewal_money,
			"beizhuMsg":beizhuMsg,
		}),
		type: "POST",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			id = data.data.id;
			alert("保存成功");
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
}
function imgSave1(){
	$.ajax({
		url: urlcore + "/api/channelBase/setImg?id="+id+"&type=1&imgStr="+JSON.stringify(img),
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			alert("保存成功");
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
	img.splice(0,img.length);
}
function imgSave2(){
	$.ajax({
		url: urlcore + "/api/channelBase/setImg?id="+id+"&type=2&imgStr="+JSON.stringify(img),
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			alert("保存成功");
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
	img.splice(0,ary.length);
	alert(img);
}
function imgSave3(){
	$.ajax({
		url: urlcore + "/api/channelBase/setImg?id="+id+"&type=3&imgStr="+JSON.stringify(img),
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			alert("保存成功");
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
	img.splice(0,ary.length);
	alert(img);
}
function imgSave4(){
	$.ajax({
		url: urlcore + "/api/channelBase/setImg?id="+id+"&type=4&imgStr="+JSON.stringify(img),
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			alert("保存成功");
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
	img.splice(0,ary.length);
	alert(img);
}
function imgSave5(){
	$.ajax({
		url: urlcore + "/api/channelBase/setImg?id="+id+"&type=5&imgStr="+JSON.stringify(img),
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			alert("保存成功");
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
	img.splice(0,ary.length);
	alert(img);
}
function imgSave6(){
	$.ajax({
		url: urlcore + "/api/channelBase/setImg?id="+id+"&type=6&imgStr="+JSON.stringify(img),
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			alert("保存成功");
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
	img.splice(0,ary.length);
	alert(img);
}
function imgSave7(){
	$.ajax({
		url: urlcore + "/api/channelBase/setImg?id="+id+"&type=7&imgStr="+JSON.stringify(img),
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			alert("保存成功");
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
	img.splice(0,ary.length);
	alert(img);
}
function imgSave8(){
	$.ajax({
		url: urlcore + "/api/channelBase/setImg?id="+id+"&type=8&imgStr="+JSON.stringify(img),
		type: "GET",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			alert("保存成功");
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
	img.splice(0,ary.length);
	alert(img);
}

function findMyCatalogue(){
	$.ajax({
		url: urlcore + "/api/roleThirdCatalogue/findAllByUser?secondTitle="+jName,
		type: "GET",
		dataType: 'json',
		async: false,
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			$.each(data.data, function(i,n) {
				arrayTitle.push(n.thirdCatalogue.title);
			});
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
}